//前台 - 客户端的clinet.js

let socket = io.connect("http://127.0.0.1:300?type=server",{
    path:"/chat"
});

socket.on("client-online-event",(data)=>{
    console.log("游客上线推送...",data);
    //渲染页面内容
    let htmlStr = "";
    $.each(data.data,(index,item)=>{
        // htmlStr+=`<div class="person" data-uid="${item.uid}">${index+1}. ${item.nick}  <span class="badge">4</span></div>`;
        htmlStr+=`<li class="person" data-uid="${item.uid}"> <a href="#"><i class="fa fa-fw fa-user"></i>${index+1}. ${item.nick}<span class="badge">4</span></a></li>`;
    });
    //插入
    $(".user-list").html(htmlStr);
    // $(".user-list2").append(htmlStr);
    $(".user-count span").eq(0).html(data.data.length);//更新在线人数
})

socket.on("server-message",(data)=>{
    console.log("已经收到游客的消息",data);
})
$("#send").click(function(){
    var content = $("textarea.form-control").val();
    console.log('发送了消息',content);
    //向客服发送消息
    socket.emit("user-message",{uid:Cookies.get("uuid"),content});
    $("textarea.form-control").val('')
})